# -*- coding: utf-8 -*-
__author__ = 'yiling'

lan = ["da","de","en-gb","en-US","es","fr","fr-ca","it","ja","nb","nl","pt","pt-br","sv","zh-CN"]
lan_map = {"English":"en-US","EN-US_DA":"da","EN-US_DE":"de","EN-UK_EN":"en-gb","EN-US_ES":"es","EN-US_ES-XL":"es-xl","EN-US_FR":"fr","EN-US_FR-CA":"fr-ca","EN-US_IT":"it","EN-US_NL":"nl","EN-US_NO-NO":"nb","EN-US_PT":"pt","EN-US_PT-BR":"pt-br","Swedish":"sv","S-Chinese":"zh-CN"}
titles = ["Key","English","EN-US_DA","EN-US_DE","EN-UK_EN","EN-US_ES","EN-US_ES-XL","EN-US_FR","EN-US_FR-CA","EN-US_IT","EN-US_NL","EN-US_NO-NO","EN-US_PT","EN-US_PT-BR","Swedish","S-Chinese"]

line = '''"country_US"	"United States"	"USA"	"Vereinigte Staaten"	"United States"	"Estados Unidos"	"Estados Unidos"	"Etats-Unis"	"États-Unis"	"Stati Uniti"	"Verenigde Staten"	"USA"	"Estados Unidos"	"Estados Unidos"	"USA"	"美国"'''
tokens = line.split('	')

max_length = 0
def paresLine(line):
    global max_length
    tokens = line.split('	')
    if len(tokens) == 1:
        return ''
    t = {}
    for i in range(1, len(tokens)):
        target = lan_map[titles[i]]
        t[target] = tokens[i]
        if len(tokens[i]) > max_length:
            max_length = len(tokens[i])
    return tokens[0], t

def fmt_word(w):
    global max_length
    return w + ' '*(max_length-len(w)+4)

ifile = open('package 1.txt', 'r')
dictionary = {}
for line in ifile.readlines():
    r = paresLine(line.replace('\n', ''))
    if r != '':
        dictionary[r[0]] = r[1]

ofile = open('result.txt', 'w')
lines = []
for k in dictionary:
    ts = []
    for l in dictionary[k]:
        ts.append(fmt_word(dictionary[k][l]))
    ofile.write('|'.join(ts))
    ofile.write('\n')

ofile.close()

class Dictionary():
    def __init__(self):
        self.dict = {}
        self.load()

    def load(self):
        pass

    def save(self):
        pass

    def parse(self):
        pass

    def translate(self, lan):
        pass